#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;
const int inf = 1e9;

int n, ch[N][2], mx[N][2], pos[N][2], mn[N][2], val[N], mnval[N], m, ans[N], ndn;

void pu(int x) {
	#define ls ch[x][0]
	#define rs ch[x][1]
	mx[x][0] = max({ mx[ls][0], mx[rs][0], pos[x][0] }); mx[x][1] = max({ mx[ls][1], mx[rs][1], pos[x][1] });
	mn[x][0] = min({ mn[ls][0], mn[rs][0], pos[x][0] }); mn[x][1] = min({ mn[ls][1], mn[rs][1], pos[x][1] });
	mnval[x] = min({ mnval[ls], mnval[rs], val[x] });
	//cerr <<"!" << x << " " << val[x] << " " <<  mnval[x] <<" " <<  mx[x][0] << " " << mx[x][1] << endl;
	#undef ls
	#undef rs
}

int x, y, a, b;

int nd(int x, int y, int v) { ++ndn; pos[ndn][0] = x; pos[ndn][1] = y; val[ndn] = v; pu(ndn); return ndn; }
int query(int o) {
	if(mn[o][0] > a || mn[o][1] > b || mx[o][0] < x || mx[o][1] < y) return inf;
	if(mn[o][0] >= x && mx[o][0] <= a && mn[o][1] >= y && mx[o][1] <= b) return mnval[o];
	if(mnval[o] > m) return mnval[o];
	return min({ query(ch[o][0]), query(ch[o][1]), (pos[o][0] >= x && pos[o][0] <= a && pos[o][1] >= y && pos[o][1] <= b ? val[o] : inf) });
}

int xl[N], xr[N], yl[N], yr[N], z[N], p[N], fa[N], rt;
int stk[N];

void build(int &o, int l, int r, int d = 0) {
	if(l > r) return; int mid = l + r >> 1; nth_element(stk + l, stk + mid, stk + r + 1, [&](auto a, auto b) { return pos[a][d] < pos[b][d]; });
	o = stk[mid]; build(ch[o][0], l, mid - 1, d ^ 1); build(ch[o][1], mid + 1, r, d ^ 1); fa[ch[o][0]] = fa[ch[o][1]] = o; pu(o);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) xl[i] = in, xr[i] = in, yl[i] = in, yr[i] = in, z[i] = in, p[i] = i;
	mn[0][0] = mn[0][1] = mnval[0] = inf; mx[0][0] = mx[0][1] = -inf; m = in; rep(i, 1, m) x = in, y = in, stk[i] = nd(x, y, i);
	build(rt, 1, m); sort(p + 1, p + n + 1, [](auto a, auto b) { return z[a] < z[b]; });
	fa[0] = 0;
	rep(i, 1, n) {
		int v = p[i]; x = xl[v]; y = yl[v]; a = xr[v], b = yr[v];
		int t = query(rt); if(t < inf) { ans[t] = v; val[t] = inf; while(t) pu(t), t = fa[t]; }
	} rep(i, 1, m) printf("%d\n", ans[i]);
	return 0;
}
